package ${packageName};

import com.baosight.iplat4j.core.util.StringUtils;
import com.baosight.iplat4j.core.data.DaoEPBase;
import com.baosight.iplat4j.core.ei.EiColumn;
import java.util.Map;
import java.util.HashMap;

/**
 * @author ${author}
 * @description ${description}实体类
 * @created by MyDevHelper
 */
public class ${name} extends DaoEPBase{
    <#list fields as field>

    /**
    * ${field.remark!''}
    */
    private ${field.type} ${field.name} = "";
    </#list>

    public ${name}(){
        initMetaData();
    }

    <#if initMetaData>
    /**
    * 初始化元数据
    */
    public void initMetaData() {
        EiColumn eiColumn;

    <#list fields as field>
        eiColumn = new EiColumn("${field.name}");
        eiColumn.setDescName("${field.remark}");
        <#--布尔值前缀is会被freemarker自动添加，使用时要自己去掉is-->
        eiColumn.setPrimaryKey(${field.pk?string("true","false")});
        eiColumn.setFieldLength(10);
        eiMetadata.addMeta(eiColumn);

    </#list>
    }
    </#if>

    /**
     *getter and setter
     */
    <#list fields as field>
    public void set${field.name?cap_first}(${field.type} ${field.name}){
        this.${field.name} = ${field.name};
    }
    public ${field.type} get${field.name?cap_first}(){
        return this.${field.name};
    }
    </#list>

    /**
    * fromMap
    */
    public void fromMap(Map map) {
        <#list fields as field>
        set${field.name?cap_first}(StringUtils.defaultIfEmpty(StringUtils.toString(map.get("${field.name}")),${field.name}));
        </#list>
    }

    /**
    * toMap
    */
    public Map toMap() {
        Map map = new HashMap();
        <#list fields as field>
        map.put("${field.name}",StringUtils.toString(${field.name}, eiMetadata.getMeta("${field.name}")));
        </#list>
        return map;
    }
}